package cn.xmu.j2ee.exp.service;

import cn.xmu.j2ee.exp.dao.OrdersDao;
import cn.xmu.j2ee.exp.dao.bo.Orders;
import cn.xmu.j2ee.exp.util.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrdersService {
    private final Logger logger = LoggerFactory.getLogger(OrdersService.class);

    private final OrdersDao ordersDao;

    @Autowired
    public OrdersService(OrdersDao ordersDao) {
        this.ordersDao = ordersDao;
    }

    /**
     * 获取某个订单信息，仅展示相关内容
     *
     * @param id 订单id
     * @return 订单对象
     */
    @Transactional(rollbackFor = {BusinessException.class})
    public Orders findOrdersByID(Long id, boolean withOrderItemByDao) throws BusinessException {
        logger.debug("findOrdersById: id = {}, withOrderItemByDao = {}", id, withOrderItemByDao);
        return ordersDao.findOrdersByID(id, withOrderItemByDao);
    }
}
